# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ruby-ox
_gemname=${pkgname#ruby-}
pkgver=2.14.17
pkgrel=1
pkgdesc="A fast XML parser and object serializer for Ruby"
url="https://github.com/ohler55/ox"
# armhf,armv7: fails to build (invalid storage class for function ...)
arch="all !armhf !armv7"
license="MIT"
checkdepends="ruby ruby-test-unit"
makedepends="ruby-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/ohler55/$_gemname/archive/v$pkgver.tar.gz
	gemspec.patch
	sax_test-omit-failing.patch
	"
builddir="$srcdir/$_gemname-$pkgver"

build() {
	gem build $_gemname.gemspec
	gem install --local \
		--install-dir dist \
		--ignore-dependencies \
		--no-document \
		--verbose \
		$_gemname

	cd dist/extensions/*/*/$_gemname-*/

	# ox expects ox.so to be in ox/ subdirectory, but does not install it here.
	mkdir ox && mv ./*.so ox/
	# Needed for tests.
	cp -l ox/*.so "$builddir"/ext/$_gemname/
}

check() {
	./test/tests.rb

	./test/sax/sax_test.rb > sax_test.log || {
		tail -n 50 sax_test.log
		return 1
	}
}

package() {
	local gemdir="$pkgdir/$(ruby -e 'puts Gem.default_dir')"
	cd "$builddir"/dist

	mkdir -p "$gemdir"
	cp -r extensions gems specifications "$gemdir"/

	# Remove unnecessary and duplicated files.
	cd "$gemdir"/gems/$_gemname-$pkgver
	rm -r ext/ lib/*.so || true
}

sha512sums="
919da1884033af0e44c7dbef78a5d08dc473967bd23a9ab445b295ae57a6f1495cc95ed88794164d96d6f000b9262fa0abce9c8b4b93d27ee4c68997c820f0c1  ruby-ox-2.14.17.tar.gz
0dfdc63ae24d2293f3bc2cab05264b054c16096dc26602f4ac896d7a0bcf4478f1d2e19dd833577fb441f8a68a06e17a817c64fdfb93d660da0f70eb4ebe3334  gemspec.patch
68ad29ceea7092eaf21a92f56092b1a075d319d2f735c9ca4688ca340cb62e44aeecd0f0b820d4444b93d37017e1ad4ac6618c5b5f86994f3a89f4a9b07fab8e  sax_test-omit-failing.patch
"
